package com.boomsecret.juc.collections;

import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * @author wangjinliang on 2019/1/23.
 */
public class ConcurrentLinkedQueueDemo {

    public static void main(String[] args) {
        ConcurrentLinkedQueue<String> concurrentLinkedQueue = new ConcurrentLinkedQueue<>();
        // add调用的就是offer
        concurrentLinkedQueue.add("aa");
        concurrentLinkedQueue.offer("cc");
        concurrentLinkedQueue.add("bb");
        concurrentLinkedQueue.offer("cc");

        for (String value : concurrentLinkedQueue) {
            System.out.println("value:" + value);
        }
        System.out.println("---------------");

        // return null if this queue is empty
        System.out.println(concurrentLinkedQueue.poll());
        System.out.println("---------------");

        for (String value : concurrentLinkedQueue) {
            System.out.println("value:" + value);
        }
        System.out.println("---------------");

        // returns null if this queue is empty
        System.out.println(concurrentLinkedQueue.peek());
        System.out.println("---------------");

        for (String value : concurrentLinkedQueue) {
            System.out.println("value:" + value);
        }
        System.out.println("---------------");

        System.out.println(concurrentLinkedQueue.isEmpty());
        System.out.println(concurrentLinkedQueue.size());
        System.out.println("---------------");

        // returns true if and only if this queue contains at least one element e such that o.equals(e)
        System.out.println(concurrentLinkedQueue.contains("cc"));
        for (String value : concurrentLinkedQueue) {
            System.out.println("value:" + value);
        }
        System.out.println("---------------");

        // Removes a single instance of the specified element from this queue
        System.out.println(concurrentLinkedQueue.remove("bb"));
        for (String value : concurrentLinkedQueue) {
            System.out.println("value:" + value);
        }
        System.out.println("---------------");
    }
}
